<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <script
    type="text/javascript"
    src="https://cdn.bootcdn.net/ajax/libs/bwip-js/3.0.4/bwip-js-min.js"
  ></script>
 
  <body>
      <canvas id="canvas"></canvas>
      <div id="output"></div>
  </body>
  <script>
    let options = "includetext parsefnc";
    let aopts = options.split(" ");
    let opts = {};
    for (let i = 0; i < aopts.length; i++) {
      if (!aopts[i]) {
        continue;
      }
      var eq = aopts[i].indexOf("=");
      if (eq == -1) {
        opts[aopts[i]] = true;
      } else {
        opts[aopts[i].substr(0, eq)] = aopts[i].substr(eq + 1);
      }
    }

    opts.text = "2022021101";
    opts.bcid = "code128";
    opts.scaleX = 2;
    opts.scaleY = 1;
    opts.textxalign = "center";

    var div = document.getElementById("output");
    if (div) div.innerHTML = "";
    try {
      // The return value is the canvas element
      let canvas = bwipjs.toCanvas("canvas", opts);
    } catch (e) {
      var s = "";
      if (e.fileName) s += e.fileName + " ";
      if (e.lineNumber) s += "[line " + e.lineNumber + "] ";
      alert(s + (s ? ": " : "") + e.message);
    }
  </script>
</html>

